<link rel="stylesheet" href="/static/cloud/css/cloud.css" />
<style type="text/css">
	.content{margin:20px;}
	.content ul{padding-top: 10px;padding-bottom: 10px}
	.content .layui-nav .url{padding-right: 0.5rem;padding-left: 0.5rem;cursor: pointer;text-align: center;line-height: 40px}
	.content .bar{margin-bottom: 0.5rem}
	.content .layui-nav{background: white;color: #6d6d6d;padding: 0}
	.content .table_file_name{color: #00986f;}
	.content .table_file_name:hover{cursor: pointer;color: #5fb878;}
	.content .forbid{color: #cacaca}
</style>
<div class="content">

	<div class="layui-row">
		<div class="layui-col-md2">
			<div id="admin_menu"></div>
		</div>
		<div class="layui-col-md10" style="padding: 20px;background-color: white;">
			<div class="layui-form layui-form-pane"   lay-filter="file_import">
			
				<blockquote class="layui-elem-quote">将物理磁盘的文件算法转移（或拷贝）到网盘路径，这样源磁盘文件即可在网盘访问文件，节约上传的繁琐操作和时间</blockquote>
			
				<div class="layui-form-item">
					<label class="layui-form-label">磁盘路径</label>
					<div class="layui-input-block">
						<input type="text" name="src_path" autocomplete="off" lay-verify="required" placeholder="请输入实际磁盘/硬盘路径"
							class="layui-input" value="">
					</div>
				</div>
			
				<div class="layui-form-item">
					<label class="layui-form-label">用户</label>
					<div class="layui-input-block">
						<select name="u_id" lay-filter="userList" id='userList'>
							<option value="0">用户1</option>
							<option value="1">用户2</option>
						</select>
					</div>
				</div>
			
				<div class="layui-form-item">
					<label class="layui-form-label">网盘路径</label>
					<div class="layui-input-block">
						<input type="text" name="pan_path" lay-verify="required" placeholder="请输入用户网盘路径" autocomplete="off"
							class="layui-input" value="">
					</div>
				</div>
			
				<div class="layui-form-item">
					<label class="layui-form-label">其他</label>
					<div class="layui-input-block">
						<input type="checkbox" name="keep_src" title="保留源文件">
						<!-- <input type="checkbox" name="like[read]" title="阅读" checked>
							<input type="checkbox" name="like[dai]" title="发呆"> -->
					</div>
				</div>
			
				<div class="layui-form-item">
					<button class="layui-btn" id="file_import_btn" lay-submit="" lay-filter="file_import_btn">保存</button>
				</div>
			</div>
			
			<div>
				<h3>说明</h3>
				<br>
				<p>保留源文件：即物理磁盘文件转移后仍保留物理磁盘的源文件，不建议保留，占据空间。</p>
				<p>网盘路径：不允许使用根路径"/"</p>
			
			</div>
		</div>
	</div>
	
</div>
<script type="text/javascript">
	layui.use(['table','form','layer'],function(){
		var table=layui.table,$=layui.$, form=layui.form, layer=layui.layer
		form.render()
		app.runTpl('admin_menu', { elem: '#admin_menu' })
		// 获取用户列表
		app.ajaxPost('/api/admin/importUserList',{},function(res){
			$('#userList').html('');
			for (let i = 0; i < res.data.length; i++) {
				const element = res.data[i];
				var html = '<option value="'+res.data[i].id+'">' + '[用户ID:'+res.data[i].id +'] '+ res.data[i].username+' ('+ res.data[i].u_name+')</option>'
				$('#userList').append(html);
			}
			form.render();
		})

		form.on('submit(file_import_btn)', function (data) {
			var data = form.val('file_import');
			if (data.keep_src == 'on') {
				data.keep_src = 1
			} else {
				data.keep_src = 0
			}
			var layerIndex = layer.load(1, {
				shade: [0.1, '#000'] //0.1透明度的白色背景
			});
			layer.msg('转移时间可能过长请耐心等待....');
			app.ajaxPost('/api/admin/importFile', data, function (res) {
				console.log(res.err_code == 1);
				layer.close(layerIndex);
				if (res.err_code == 0) {
					layer.msg('导入完成');
				} else {
					layer.alert('导入失败，' + res.err_msg);
				}
			},function(){
				layer.close(layerIndex);
				layer.alert('导入失败，错误代码：500');
			})
			return false; //阻止表单跳转
		});
		

	})
</script>